package com.wetalk.utils;

import org.springframework.stereotype.Service;

import java.security.SecureRandom;
/**
 * @author lijiaxing 2025-7-5
 */
@Service
public class VerificationCodeCreater {
    // 验证码字符范围：0-9, a-z, A-Z
    private static final String SCOPE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final int LENGTH = 4;

    public String generateCode() {
        SecureRandom random = new SecureRandom();
        StringBuilder code = new StringBuilder(LENGTH);

        for (int i = 0; i < LENGTH; i++) {
            int index = random.nextInt(SCOPE.length());
            code.append(SCOPE.charAt(index));
        }

        return code.toString();
    }

    public static void main(String[] args) {
        String code = new VerificationCodeCreater().generateCode();
        System.out.println("验证码: " + code);
    }
}
